//
//  NvTimelineImageUtils.m
//  SDKDemo
//
//  Created by shizhouhu on 2018/7/9.
//  Copyright © 2018年 meishe. All rights reserved.
//

#import "NvTimelineImageUtils.h"
#import "NvsStreamingContext.h"
#import "NvTimelineData.h"
#import "NvUtils.h"
#import "NvsVideoTrack.h"
#import "NvsVideoClip.h"

@implementation NvTimelineImageUtils

+ (UIImage *)getImageWithTime:(NvsTimeline *)timeline time:(int64_t)time {
    return [[NvsStreamingContext sharedInstance] grabImageFromTimeline:timeline timestamp:time proxyScale:nil];
}

+ (UIImage *)getImageWithClipInfo:(NvsTimeline *)timeline clipInfo:(NvEditDataModel *)clipInfo {
    NSMutableArray *editDataArray = [[NvTimelineData sharedInstance] editDataArray];
    for (int i = 0; i < editDataArray.count; i++) {
        NvEditDataModel *info = editDataArray[i];
        if ([info.uuid isEqualToString:clipInfo.uuid]) {
            NvsVideoTrack *videoTrack = [timeline getVideoTrackByIndex:0];
            NvsVideoClip *clip = [videoTrack getClipWithIndex:i];
            return [NvTimelineImageUtils getImageWithTime:timeline time:clip.inPoint];
        }
    }
    return nil;
}

+ (UIImage *)getImageWithClipInfo:(NvsTimeline *)timeline clipInfo:(NvEditDataModel *)clipInfo proxyScale:(const NvsRational *)proxyScale{
    NSMutableArray *editDataArray = [[NvTimelineData sharedInstance] editDataArray];
    for (int i = 0; i < editDataArray.count; i++) {
        NvEditDataModel *info = editDataArray[i];
        if ([info.uuid isEqualToString:clipInfo.uuid]) {
            NvsVideoTrack *videoTrack = [timeline getVideoTrackByIndex:0];
            NvsVideoClip *clip = [videoTrack getClipWithIndex:i];
            return [[NvsStreamingContext sharedInstance] grabImageFromTimeline:timeline timestamp:clip.inPoint proxyScale:proxyScale];
        }
    }
    return nil;
}

@end
